import java.util.Arrays;

public class Solution1365 {
    public int[] smallerNumbersThanCurrent(int[] nums) {
        int[] c=new int[101];
        for (int num : nums) {
            c[num]++;
        }
        int[] sum=new int[101];
        sum[0]=c[0];
        for (int i=1;i<=100;i++){
            sum[i]=sum[i-1]+c[i];
        }
        int[] ans=new int[nums.length];
        for (int i=0;i<nums.length;i++){
            ans[i]=nums[i]==0?0:sum[nums[i]-1];
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution1365().smallerNumbersThanCurrent(new int[]{8, 1, 2, 2, 3})));
    }
}
